package com.xzj.springmvc.controller;

import com.xzj.spring.annotation.Autowired;
import com.xzj.springmvc.annotation.*;
import com.xzj.springmvc.entity.po.User;
import com.xzj.springmvc.entity.vo.UserVO;
import com.xzj.springmvc.service.impl.UserServiceImpl;

import java.util.Base64;

/**
 * @ProjectName: SpringDemo
 * @Package: com.xzj.springmvc.controller
 * @ClassName: HelloController
 * @Author: xzj
 * @Description:
 * @Date: 2022/7/14 16:48
 * @Version: 1.0
 */
@RestController("myHello2Controller")
@RequestMapping("/hello2")
public class Hello2Controller {

    @Autowired
    UserServiceImpl userService;

//    @RequestMapping("/hello222222")
//    public String hello(String username,String password,@RequestParam("user") UserVO userVO) {
//        User user = new User();
//        user.setUsername(userVO.getUsername());
//        user.setPassword(Base64.getEncoder().encodeToString(userVO.getPassword().getBytes()));
//        System.out.println(userVO);
//        System.out.println(user);
//        userService.logging(user);
//        return "123";
//    }

    @GetMapping("/")
    public String query(String username,String password, UserVO userVO) {
        User user = new User();
        user.setUsername(userVO.getUsername());
        user.setPassword(Base64.getEncoder().encodeToString(userVO.getPassword().getBytes()));
        System.out.println(userVO);
        System.out.println(user);
        userService.logging(user);
        return "query";
    }

    @PostMapping("/")
    public String save(String username,@RequestParam String password,@RequestBody(required = false) UserVO userVO) {
        User user = new User();
        user.setUsername(userVO.getUsername());
        user.setPassword(Base64.getEncoder().encodeToString(userVO.getPassword().getBytes()));
        System.out.println(userVO);
        System.out.println(user);
        userService.logging(user);
        return "save";
    }

}
